import 'package:pacsun/components/appbar.dart';
import 'package:pacsun/view/create/become/component/BeComebtn.dart';
import 'package:pacsun/view/create/become/component/Community.dart';
import 'package:pacsun/view/create/become/component/FeaturedCreators.dart';
import 'package:pacsun/view/create/become/component/Header.dart';
import 'package:pacsun/view/create/become/component/Moments.dart';
import 'package:pacsun/view/create/become/component/YouNeed.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class BeComePage extends StatefulWidget {
  const BeComePage({super.key});

  @override
  State<BeComePage> createState() => _BeComePage();
}

class _BeComePage extends State<BeComePage> {
  Color appBarColor = Colors.transparent;
  final ScrollController scrollController = ScrollController();

  @override
  void initState() {
    super.initState();
    scrollController.addListener(() {
      double offset = scrollController.offset;
      if (offset > 100) {
        setState(() {
          appBarColor = Colors.black;
        });
      } else {
        setState(() {
          appBarColor = Colors.transparent;
        });
      }
    });
  }

  @override
  void dispose() {
    scrollController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    // 底部自适应高度
    final bottomPadding = MediaQuery.of(context).padding.bottom;
    return MediaQuery(
      data: MediaQuery.of(context).copyWith(textScaler: TextScaler.noScaling),
      child: Scaffold(
        appBar: CommonTransparentAppBar(
          backgroundColor: appBarColor,
          height: 40.h,
        ),
        extendBodyBehindAppBar: true,
        body: Stack(
          children: [
            SingleChildScrollView(
              controller: scrollController,
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  const Header(),
                  const Community(),
                  const FeaturedCreators(),
                  const YouNeed(),
                  const Moments(),
                ],
              ),
            ),
            Positioned(
              bottom: bottomPadding,
              left: 20.w,
              child: const BeComebtn(),
            )
          ],
        ),
      ),
    );
  }
}
